# _*_ coding:UTF-8 _*_

import yaml
import os


# class confYml(object):
#
#     def __init__(self, path):
#         self.path = path
#         self.cr = configparser.ConfigParser()
#         self.cr.read(path, encoding="utf-8-sig")
#
#     def get(self, section, key):
#         try:
#             result = self.cr.get(section, key)
#         except configparser.NoOptionError as err:
#             print("configparser.NoOptionError: ", err)
#             result = ""
#         except configparser.NoSectionError as err:
#             print("configparser.NoSectionError: ", err)
#             result = ""
#         return result
#
#     def set(self, section, key, value):
#         # noinspection PyBroadException
#         try:
#             config = open(self.path, 'w')
#             self.cr.set(section, key, value)
#             self.cr.write(config)
#             config.close()
#         except:
#             return False
#         return True


# 获取当前文件的path
filePath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# print(filePath)
ymlPath = filePath +"/data/conf.yml"
# # print(ymlPath)
# # encoding='utf-8'，处理配置文件中含中文出现乱码的情况。
# f = open(ymlPath, 'a', encoding='utf-8')
# cont = f.read()
# x = yaml.load(cont)
# print(x['Basic']['os'])
# print(x.get('Basic').get('os'))

# 写入yaml 文件
# a 追加写入，w,覆盖写入
# fw = open(ymlPath,'a',encoding='utf-8')
# # 构建数据
# data = {"cookie1":{'domain': '.yiyao.cc', 'expiry': 1521558688.480118, 'httpOnly': False, 'name': '_ui_', 'path': '/', 'secure': False, 'value': 'HSX9fJjjCIImOJoPUkv/QA=='}}
# # 装载数据
# yaml.dump(data,fw)
# # 读取数据，获取文件
# f = open(ymlPath,'r',encoding='utf-8')
# # 读取文件
# cont = f.read()
# # 加载数据
# x = yaml.load(cont)
# # 打印数据
# print(x)
# # 打印读取写入的数据
# print(x.get("cookie1"))